import { PaginationParam, PaginationResult } from "../../models";
import { WorkOrderItem } from "../serviceWorkOrder/models";
import { AlarmItem, AlarmResponse, PartialSearchAlarmReq, TransWorkOrderReq } from "./models";
import req from "/@/api/req";

export enum Api {
  getAlarmEventsById = "api/v1/projects/alarms/get",
  pageAlarmEvents = "api/v1/projects/alarms/page",
  hisPageAlarmEvents = "api/v1/projects/alarms/history/page",
  updateAlarmEvents = "api/aiot/alarmEvents/updateAlarmEvents",
  confirmAlarmEvents = "api/v1/projects/alarms/confirm", // 确认故障
  deactivateAlarmEvents = "api/v1/projects/alarms/deactivate", // 解除故障
  dismissAlarmEvents = "api/v1/projects/alarms/dismiss", // 忽略故障
  countAlarmEvents = "api/v1/projects/alarms/count", // 告警统计 历史和当前
  transferToWorkOrder = "api/v1/projects/alarms/transferToWorkOrder", // 转工单
}

// 告警统计
export function countAlarmEvents(data: { equipmentId?: string; projectId?: string }) {
  return req.post<{ currentAlarmEventCount: number; historyAlarmEventCount: number }>(
    {
      url: Api.countAlarmEvents,
      data,
    },
    {
      useGlobalLoading: false,
    }
  );
}
// 确认故障
export function confirmAlarmEvents(data: { alarmEventId: string; remark: string }) {
  return req.post<boolean>({
    url: Api.confirmAlarmEvents,
    data,
  });
}
// 解除故障
export function deactivateAlarmEvents(data: { alarmEventId: string; remark: string }) {
  return req.post<boolean>({
    url: Api.deactivateAlarmEvents,
    data,
  });
}
// 忽略故障
export function dismissAlarmEvents(data: { alarmEventId: string }) {
  return req.post<boolean>({
    url: Api.dismissAlarmEvents,
    data,
  });
}
// 获取告警详情
export function getAlarmEventsById(alarmEventId: string) {
  return req.post<AlarmResponse>({
    url: Api.getAlarmEventsById,
    data: { alarmEventId },
  });
}
// 修改状态
export function updateAlarmEvents(data: PartialSearchAlarmReq) {
  return req.post<boolean>({
    url: Api.updateAlarmEvents,
    data,
  });
}
// 修改状态
export function transferToWorkOrder(data: TransWorkOrderReq) {
  return req.post<boolean>({
    url: Api.transferToWorkOrder,
    data,
  });
}
// 查询列表
export function pageAlarmList(model: PartialSearchAlarmReq, loading = false) {
  return req.post<PaginationResult<AlarmItem>>(
    {
      url: Api.pageAlarmEvents,
      data: {
        current: 1,
        size: 999,
        model,
      },
    },
    {
      useGlobalLoading: loading,
    }
  );
}
